package com.mvc.app.implementations;

import com.container.app.MContainer;
import com.container.app.annotations.Component;
import com.mvc.app.ActionRequest;
import com.mvc.app.ActionRequestGenerator;

import java.lang.reflect.Method;

import static com.mvc.app.utils.MVCUtils.*;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 8/29/12
 * Time: 12:24 PM
 */
@Component
public class ActionRequestGeneratorImplFromPath implements ActionRequestGenerator {

    public ActionRequestGeneratorImplFromPath() {
    }

    public ActionRequest createActionRequest(MContainer container, String additionalInfo) {

        Object controller;
        Method controllerMethod;
        String controllerName = getControllerNameFromPath(additionalInfo);
        String controllerMethodName = getControllerMethodNameFromPath(additionalInfo);

        controller = getControllerInstance(container, controllerName);
        controllerMethod = getMethodWithAnnotationName(controller.getClass(), controllerMethodName);

        return new ActionRequest(controller, controllerMethod);
    }
}
